from functools import wraps
from flask import request, jsonify

def require_json(f):
    """要求请求必须是JSON格式的装饰器"""
    @wraps(f)
    def decorated(*args, **kwargs):
        if not request.is_json:
            return jsonify({
                "code": 400,
                "message": "请求必须是JSON格式"
            }), 400
        return f(*args, **kwargs)
    return decorated